class Comment {
  final int id;
  final String content;
  final String username;
  final String avatar;
  final String createdAt;
  final List<Comment> replies;

  Comment({
    required this.id,
    required this.content,
    required this.username,
    required this.avatar,
    required this.createdAt,
    required this.replies,
  });

  factory Comment.fromJson(Map<String, dynamic> json) {
    return Comment(
      id: (json['id'] ?? 0) as int,
      content: (json['content'] ?? '') as String,
      username: (json['username'] ?? '') as String,
      avatar: (json['avatar'] ?? '') as String,
      createdAt: (json['createdAt'] ?? '') as String,
      replies: ((json['replies'] ?? []) as List)
          .map((e) => Comment.fromJson(e as Map<String, dynamic>))
          .toList(),
    );
  }
}
